package cn.touna.jss.modules.custom.carmodel.synctask;

import cn.touna.jss.modules.custom.carmodel.dto.TaskInfo;
import cn.touna.jss.modules.custom.carmodel.synctask.CarModelSyncTaskExecutor;
import cn.touna.jss.modules.custom.carmodel.synctask.DateDistributeTaskId;
import org.apache.commons.lang3.StringUtils;
import org.quartz.DisallowConcurrentExecution;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.quartz.QuartzJobBean;
import org.springframework.stereotype.Component;

/**
 * Created by Steve.Tao on 2017/11/22.
 */
@Component
@DisallowConcurrentExecution
public class SyncCarModelTask extends QuartzJobBean {

    @Autowired
    private DateDistributeTaskId dateDistributeTaskId;

    @Autowired
    private CarModelSyncTaskExecutor carModelSyncTaskExecutor;

    @Override
    protected void executeInternal(JobExecutionContext context) throws JobExecutionException {
        TaskInfo taskInfo = new TaskInfo();
        taskInfo.setType(CarModelSyncTaskExecutor.TASK_SYNC_CAR_MODEL);
        taskInfo.setDesc("同步车型库，包括车300和精真估");
        String taskId = dateDistributeTaskId.getTaskId(taskInfo);
        if (StringUtils.isBlank(taskId))
            return;
        carModelSyncTaskExecutor.doTask(taskId, taskInfo);
    }
}
